package com.newtouch.bxzs.common.base.config;

import com.newtouch.bxzs.common.base.constant.RabbitMQConstant;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * RabbitMQ配置类
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2020年12月28日</td>
 * <td>Amour</td>
 * <td>Create</td>
 * </tr>
 * </table>
 * 
 * @author Amour
 * 
 * @version 1.0.0
 * @since 1.0.0
 */
@Configuration
public class TopicRabbitConfig {

	/**
	 * 通知队列
	 *
	 * @return
	 */
	@Bean
	public Queue queueMessageNotice() {
		return new Queue(RabbitMQConstant.MESSAGE_NOTICE);
	}

	/**
	 * pc端维护的通知队列
	 *
	 * @return
	 */
	@Bean
	public Queue queueMessagePcNotice() {
		//持久化队列 默认都是持久化
//		return new Queue(RabbitMQConstant.PC_MESSAGE_NOTICE,true);
		return QueueBuilder.durable(RabbitMQConstant.PC_MESSAGE_NOTICE).build();
	}

	@Bean
	TopicExchange exchange() {
		//持久化交换机 默认都是持久化
		return new TopicExchange(RabbitMQConstant.EXCHANGE_STR,true,false);
	}

	/**
	 * 通知信息队列和交换机绑定
	 *
	 * @return
	 */
	@Bean
	Binding bindingExchangeMessageNotice() {
		return BindingBuilder.bind(this.queueMessageNotice()).to(exchange()).with(RabbitMQConstant.MESSAGE_NOTICE);
	}

	/**
	 * pc通知信息队列和交换机绑定
	 * @return
	 */
	@Bean
	Binding bindingExchangeMessagePcNotice() {
		return BindingBuilder.bind(this.queueMessagePcNotice()).to(exchange()).with(RabbitMQConstant.PC_MESSAGE_NOTICE);
	}
}
